package com.songlanyun.modules.goodsuserdiscount.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.utils.SpringContextUtils;
import com.songlanyun.common.validator.group.AddGroup;
import com.songlanyun.common.validator.group.UpdateGroup;
import com.songlanyun.modules.goods.service.GoodsContentService;
import com.songlanyun.modules.goodsuserdiscount.service.GoodsUserDiscountDetailService;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;

/**
 * 商品会员折扣配置
 * 
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-13 09:54:23
 */
@Data
@TableName("yxt_product_goods_user_discount_config")
public class GoodsUserDiscountConfig extends RootEntity<Long,GoodsUserDiscountConfig> implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	@TableId
	private Long id;
	/**
	 *  商品id
	 */

	@NotNull(message = "必须指定商品Id")
	private Long goodsId;
	/**
	 * 是否使用默认(是否使用店铺级的会员等级折扣)
	 */
	private Boolean useDefault;


	@TableField(fill = FieldFill.INSERT)
	private Date createTime;
	/**
	 *
	 */
	@TableField(fill = FieldFill.INSERT_UPDATE)
	private Date updateTime;

	@Override
	public Long getIdentity() {
		return getId();
	}

	@TableField(exist = false)
	private List<GoodsUserDiscountDetail> details;

	public List<GoodsUserDiscountDetail> getDetails()
	{
		if(details==null)
		{
			GoodsUserDiscountDetailService service = ((GoodsUserDiscountDetailService) SpringContextUtils.getBean("goodsUserDiscountDetailService"));
			List<GoodsUserDiscountDetail> list = service.list(new LambdaQueryWrapper<GoodsUserDiscountDetail>()
					.eq(GoodsUserDiscountDetail::getGoodsId, this.goodsId));
			details = list;
		}

		return details;
	}
}
